<template>
    <div class="container">
        <el-tabs v-model="url" @tab-click="handleClick">
            <el-tab-pane label="账户管理" name="accountList"></el-tab-pane>
            <el-tab-pane label="角色管理" name="roleList"></el-tab-pane>
        </el-tabs>
        <div class="input_modal">
            <div class="input-item">
                <el-button icon="el-icon-edit" type="primary" size='medium' @click="addItem">新增账户</el-button>
            </div>
            <div class="input-item">
                <span>手机号：</span>
                <el-input v-model="mobile" placeholder="请输入内容" class="" @keyup.enter.native="search"></el-input>
            </div>
             <div class="input-item">
                <span>姓名：</span>
                <el-input v-model="trueName" placeholder="请输入内容" class="" @keyup.enter.native="search"></el-input>
                <el-button type="primary" size='medium' @click="getAccountList(1)">查询</el-button>
            </div>
        </div>
        <div class="table_con">
            <el-table v-loading="loading"  :data="tableData"  :border='true' >
                  <el-table-column  prop="userName"    label="登录名"></el-table-column>
                  <el-table-column  prop="trueName" label="姓名"></el-table-column>
                  <el-table-column  prop="mobile" label="手机"></el-table-column>
                  <el-table-column  prop="roleName" label="所属角色"></el-table-column>
                  <el-table-column  prop=""  label="操作" fixed="right" width='140'>
                      <template slot-scope="scope">
                          <el-button icon="el-icon-edit" class="link" type="info" size="mini">
                               <router-link :to="{ name: 'accountEdit', query: {userId:tableData[scope.$index].userId,pageIndex:pageIndex}}"  style="color: #fff;">编辑</router-link>
                          </el-button>
                          <el-button icon="el-icon-delete" type="danger" size="mini" @click="deleteAccount(tableData[scope.$index].userId)">删除</el-button>
                      </template>
                  </el-table-column>
            </el-table>
        </div>

        <div class="pagination">
             <el-pagination   @size-change="handleSizeChange"  @current-change="handleCurrentChange"       
                :current-page.sync="pageIndex"              
                :page-size="pageSize"   
                :page-sizes='[10,20,30,40]'    
                layout="sizes, prev, pager, next"       
                :total="pageCount">     
            </el-pagination>
        </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
export default {
    data() {
        return { 
            tableData:[],
            trueName:'',
            mobile:'',
            pageCount:null,
            pageIndex:1,
            pageSize:10,
            url: 'accountList',
        }
    },
    mounted() {
        this.pageIndex = this.$router.currentRoute.query.currentPage?this.$router.currentRoute.query.currentPage:1;
        this.getAccountList();
    },
    methods: {
        getAccountList:function(){
           let url = CONSTANT.URL.SYSTEM.FINDADMINUSERBYPAGE;
           let param = {
               pageIndex:this.pageIndex,
               pageSize:this.pageSize,
               trueName:this.trueName,
               mobile:this.mobile
           };
           this.loading = true;
            common.requestAjax(url,null,param,(res)=>{
                this.loading = false;
                let data = res.data;
                this.tableData = data.bussData;
                this.pageCount = data.count;
            }) 
        },
        deleteAccount:function(id) {
            this.$confirm('确定删除?', '提示', {           
                confirmButtonText: '确定',           
                cancelButtonText: '取消',           
                type: 'warning'         
            }).then(() => {           
                let  url = CONSTANT.URL.SYSTEM.DELETEADMINUSERBYID;
                let param = {userId:id} ;
                // let param = JSON.stringify(data);
                common.requestAjax(url,null,param,(res)=>{
                    if(res.status == 200){
                        this.$message({
                            type:'success',
                            message:'删除成功!'
                        });
                        this.getAccountList();
                    }
                    else{
                        this.$message({
                            type:'warning',
                            message:res.msg
                        })
                    }
                })      
            }).catch(() => {           
                this.$message({             
                    type: 'info',             
                    message: '已取消删除'           
                });                   
            });    
        },
        addItem(){
            this.$router.push('/accountEdit')
        },
        search:function(e){
            if(e.keyCode == 13){
                this.pageIndex = 1;
                this.getAccountList(); 
            }
        },
        handleSizeChange(val) {
            this.pageSize= val;
            this.getAccountList();
        },
        handleCurrentChange(val) {
            this.pageIndex = val;
            this.getAccountList();
        },
        handleClick() {
            let url = '/'+ this.url;
            this.$router.push(url);
        },
    },
    filters:{
    
    }
}
</script>
